﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using nspJob;
using Base;

public partial class Member_Job_CompanyResumeManager : BasePage
{
    string strWhere = " 1=1 ";
    DataTable dt = new DataTable();
    protected void Page_Load(object sender, EventArgs e)
    {

        if (!IsPostBack)
        {
            if (!CheckCookies())
            {
                Response.Redirect("../../login/login.aspx");
            }
            else
            {
                this.grdJob.DataKeyNames = new string[] { "id" };//绑定datakeyNames

                //判断用户时候有权限
                PositionTypeBind();//绑定企业发布职位名称
                Bind();//绑定数据
            }
        }

    }
    ///**************************************************
    /// <summary>
    /// depiction：此方法用于绑定数据
    /// </summary>
    /// <param name="<参数名称>"><参数说明></param>
    /// <returns>
    ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
    /// </returns>
    ///Create Date：2009-9-3
    ///**************************************************
    private void Bind()
    {
        
        int userid = Convert.ToInt32(GetRequest.GetCookie("UserID").ToString());//获取企业编号 
        strWhere += " and c.UserID=" + userid;
        int PageIndex = 0;
        if (HttpContext.Current.Request.QueryString["page"] != null)
            PageIndex = Convert.ToInt32(Request.QueryString["Page"].ToString());
        if (PageIndex <= 0) PageIndex = 1;

        if (!string.IsNullOrEmpty(this.HiddenField1.Value))
        {
            strWhere += "  a.typeid =";
            strWhere += this.HiddenField1.Value;
        }

        string strURl = Request.RawUrl;
        strURl = strURl.Substring(0, strURl.IndexOf(".aspx")) + ".aspx";
        PageNo1.Strurl = strURl;
        PageNo1.FldName = "b.AddDate";
        PageNo1.Table = "C_JobResume as a inner join U_Resume  as b on(a.ResumeID=b.ID) inner join C_Job as c on(a.jobID=c.ID)";
        PageNo1.StrGetFields = "a.ResumeID,a.Mark,b.ID,B.Name,b.isEnable,c.Position,b.TalentType,b.HighestEducation,b.ContactAddress,b.Telephone,b.Mobile,b.AddDate";
        PageNo1.PageSize = 12;

        if (Request.QueryString["page"] != "" && Request.QueryString["page"] != null)
        {
            PageNo1.Pageindex = Int32.Parse(Request.QueryString["page"].ToString());
            if (Session["strWhere"] != null)
                strWhere = Session["strWhere"].ToString();
            PageNo1.Where = strWhere;
            dt = PageNo1.BindViewDesc();
        }
        else
        {
            PageNo1.Pageindex = 1;
            PageNo1.Where = strWhere;
            Session["strWhere"] = strWhere;
            dt = PageNo1.BindViewDesc();
        }
        if (dt.Rows.Count == 0)
        {
            grdJob.DataSource = dt.DefaultView;
            grdJob.DataBind();
            dt.Clear();
            dt.Dispose();
        }
        else
        {
            grdJob.DataSource = dt.DefaultView;
            grdJob.DataBind();
            dt.Clear();
            dt.Dispose();
        }

    }
    public string GetShortDate(string dateStr)
    {
        if (dateStr != string.Empty)
            return Convert.ToDateTime(dateStr).ToShortDateString();
        else
            return String.Empty;
    }
    ///**************************************************
    /// <summary>
    /// depiction：此方法用于对简历是否发布
    /// </summary>
    /// <param name="<参数名称>"><参数说明></param>
    /// <returns>
    ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
    /// </returns>
    ///Create Date：2009-9-3
    ///**************************************************
    public string RelaseState(bool tmp)
    {
        string Str = "暂停";
        if (!tmp)
            Str = "发布";
        return Str;
    }
    ///**************************************************
    /// <summary>
    /// depiction：此方法用于单个删除
    /// </summary>
    /// <param name="<参数名称>"><参数说明></param>
    /// <returns>
    ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
    /// </returns>
    ///Create Date：2009-9-3
    ///**************************************************
    protected void grdJob_RowDeleting(object sender, GridViewDeleteEventArgs e)
    {
        int ID = Convert.ToInt32(grdJob.DataKeys[e.RowIndex].Value);
        IResume rm = new RResume();
        rm.Delete(ID);
        Bind();
    }

    ///**************************************************
    /// <summary>
    /// depiction：此方法用于批量删除
    /// </summary>
    /// <param name="<参数名称>"><参数说明></param>
    /// <returns>
    ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
    /// </returns>
    ///Create Date：2009-9-2
    ///**************************************************
    protected void btnDelete_Click(object sender, EventArgs e)
    {
        for (int i = 0; i < grdJob.Rows.Count; i++)
        {
            CheckBox cbox = grdJob.Rows[i].FindControl("CheckBox1") as CheckBox;
            if (cbox.Checked == true)
            {
                int id = int.Parse(grdJob.DataKeys[i].Value.ToString());
                IResume rm = new RResume();
                rm.Delete(id);
            }
        }
        Bind();
    }
    protected void grdJob_RowDataBound(object sender, GridViewRowEventArgs e)
    {
        showToolTip(e);
        if (e.Row.RowType == DataControlRowType.DataRow)
        {
            e.Row.Attributes.Add("onMouseOver", "SetNewColor(this);");
            e.Row.Attributes.Add("onMouseOut", "SetOldColor(this);");
        }
        showToolTip(e);
    }
    ///**************************************************
    /// <summary>
    /// depiction：对职位类别绑定
    /// </summary>
    /// <param name="<参数名称>"><参数说明></param>
    /// <returns>
    ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
    /// </returns>
    ///Create Date：2009-9-1
    ///**************************************************
    private void PositionTypeBind()
    {

        Rjob jobtype = new Rjob();
        DataTable dt = jobtype.GetDataType("C_Job");
        dropTypeID.DataSource = dt.DefaultView;
        dropTypeID.DataValueField = "Position";
        dropTypeID.DataTextField = "Position";
        dropTypeID.DataBind();
        dropTypeID.Items.Insert(0, new ListItem("不限", "0"));

    }
    ///**************************************************
    /// <summary>
    /// depiction：此方法用于查询
    /// </summary>
    /// <param name="<参数名称>"><参数说明></param>
    /// <returns>
    ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
    /// </returns>
    ///Create Date：2009-9-2
    ///**************************************************
    protected void btnSelect_Click(object sender, EventArgs e)
    {
        string name = this.txtname.Text.Trim();
        if (name != "")
            name = Base.GetRequest.Filter(name);
        string positonName = dropTypeID.SelectedValue.ToString();
        string mark = this.drpResume.SelectedValue.ToString();
        if (!positonName.Equals("0"))
        {
            strWhere += " and c.Position ='" + positonName + "'";
        }
        if (!string.IsNullOrEmpty(name))
        {
            strWhere += " and b.Name like '%" + name + "%'";
        }
        if (!mark.Equals("0"))
        {
            strWhere += " and a.Mark ='" + mark + "'";
        }
        Session["strWhere"] = strWhere;
        Bind();
    }

    protected void dropTypeID_SelectedIndexChanged(object sender, EventArgs e)
    {
        this.HiddenField1.Value = this.dropTypeID.SelectedValue;
    }
    ///**************************************************
    /// <summary>
    /// depiction：此方法用于对职位是否通过审核赋值
    /// </summary>
    /// <param name="<参数名称>"><参数说明></param>
    /// <returns>
    ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
    /// </returns>
    ///Create Date：2009-9-7
    ///**************************************************
    public string turncn(int tmp)
    {
        string Str = "符合";
        if (tmp == 3)
        {
            Str = "不符合";
        }
        if (tmp == 2)
        {
            Str = "最符合";
        }
        return Str;
    }
    ///**************************************************
    /// <summary>
    /// depiction：此方法用于显示小提示
    /// </summary>
    /// <param name="<参数名称>"><参数说明></param>
    /// <returns>
    ///<对方法返回值的说明，该说明必须明确说明返回的值代表什么含义>
    /// </returns>
    ///Create Date：2009-9-2
    ///**************************************************
    private static void showToolTip(GridViewRowEventArgs e)
    {
        string name = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "name"));
        string address = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "ContactAddress"));
        string telephone = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Telephone"));
        string mobile = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "Mobile"));
        string registerTime = Convert.ToString(DataBinder.Eval(e.Row.DataItem, "AddDate"));
        e.Row.ToolTip = "姓名：" + name + "\n联系地址：" + address + "\n手机：" + telephone + "\n电话：" + mobile + "\n登记时间：" + registerTime;
    }
}
